package rhc.discribute.access;

import java.util.Collection;
import java.util.concurrent.TimeUnit;

import rhc.discribute.access.signal.HostJoin;
import rhc.discribute.access.signal.HostRemove;
import rhc.discribute.access.signal.MainConnect;
import rhc.discribute.access.signal.MainDisConnect;
import rhc.discribute.access.signal.NoMain;
import rhc.discribute.access.signal.ReceiveMsg;
import rhc.discribute.access.signal.SendMsgCallback;
import rhc.discribute.node.commander.Commander;
import rhc.discribute.node.commander.impl.CommanderImpl;
import rhc.discribute.node.connecter.Connecter;
import rhc.discribute.node.host.Host;
import rhc.discribute.node.sendMessage.SendMessageCallback;
import rhc.discribute.signal.Signal;

public class Access {

	public static void main(String[] args) throws Exception{
		Commander commander=new CommanderImpl();
		
		commander.getSignalManage().connect(Signal.HOST_JOIN, new HostJoin());
		commander.getSignalManage().connect(Signal.HOST_REMOVE, new HostRemove());
		commander.getSignalManage().connect(Signal.MAIN_CONNECT, new MainConnect());
		commander.getSignalManage().connect(Signal.MAIN_DIS_CONNECT, new MainDisConnect());
		commander.getSignalManage().connect(Signal.NO_MAIN, new NoMain());
		commander.getSignalManage().connect(Signal.RECEIVE_MSG, new ReceiveMsg());
		
		commander.begin();
		
		SendMessageCallback callback=new SendMsgCallback();
		
		Connecter connecter=commander.getConnecter();
		
		
		while(true){
			Thread.sleep(TimeUnit.SECONDS.toMillis(10));
			Collection<Host> hostSet=commander.getNodeManage().getAllHost();
			
//			for(Host host:hostSet){
//				connecter.sendMessageToHost(host, "adfdasfdsafdsdddd",callback,false);
//			}
		}
		
		
		
//		Thread.sleep(TimeUnit.DAYS.toMillis(30));
	}
	
}
